package javaapplication1.dao.oracleImpl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javaapplication1.tool.PropertiesUtil;

public class OracleConnection {

	public static Connection getConnection() {
		Connection connection = null;
		String driver = PropertiesUtil.getValue(
				"src/dao/oracleImpl/oracle.properties", "driver");
		String user = PropertiesUtil.getValue(
				"src/dao/oracleImpl/oracle.properties", "user");
		String password = PropertiesUtil.getValue(
				"src/dao/oracleImpl/oracle.properties", "password");
		String url = PropertiesUtil.getValue(
				"src/dao/oracleImpl/oracle.properties", "url");
		try {
			Class.forName(driver);
			connection = DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			System.out.println("数据库连接失败");
			e.printStackTrace();
		}
		return connection;
	}

	public static void closeConn(Connection connection, PreparedStatement ps,
			ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
			if (ps != null) {
				ps.close();
				ps = null;
			}
			if (connection != null) {
				connection.close();
				connection = null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}